<script lang="ts" setup>
import { ref } from 'vue';
import { currentCourse, formLoading, operationType, onSaveCourse } from './utils/hooks';

// 表单ref
const formRef = ref();
// 表单规则
const rules = {
  code: [{ required: true, message: '请输入课程编码', trigger: 'blur' }],
  name: [{ required: true, message: '请输入课程名称', trigger: 'blur' }],
  description: [{ required: true, message: '请输入课程描述', trigger: 'blur' }],
  credit: [
    { required: true, message: '请输入课程学分', trigger: 'blur' },
    { type: 'number', message: '学分必须为数字', trigger: 'blur' }
  ],
};

// 暴露onSaveCourse方法以供父组件调用
defineExpose({ onSaveCourse, formRef });
</script>

<template>
  <el-form ref="formRef" :model="currentCourse" :rules="rules" label-position="right" label-width="100px">
    <!-- 课程编码 -->
    <el-form-item label="课程编码" prop="code">
      <el-input v-model="currentCourse.code" placeholder="请输入课程编码" />
    </el-form-item>
    
    <!-- 课程名称 -->
    <el-form-item label="课程名称" prop="name">
      <el-input v-model="currentCourse.name" placeholder="请输入课程名称" />
    </el-form-item>

    <!-- 课程学分 -->
    <el-form-item label="课程学分" prop="credit">
      <el-input-number v-model="currentCourse.credit" :min="0" :precision="1" :step="0.5" placeholder="请输入课程学分" />
    </el-form-item>

    <!-- 课程描述 -->
    <el-form-item label="课程描述" prop="description">
      <el-input
        v-model="currentCourse.description"
        :autosize="{ minRows: 3, maxRows: 6 }"
        placeholder="请输入课程描述"
        type="textarea"
      />
    </el-form-item>
  </el-form>
</template> 